package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysRole;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysIdentityType;
import com.ruoyi.system.service.ISysIdentityTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 证件类型Controller
 *
 * @author ruoyi
 * @date 2024-07-30
 */
@RestController
@RequestMapping("/system/identitytype")
public class SysIdentityTypeController extends BaseController {
    @Autowired
    private ISysIdentityTypeService sysIdentityTypeService;

    /**
     * 查询证件类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:identitytype:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysIdentityType sysIdentityType) {
        startPage();
        List<SysIdentityType> list = sysIdentityTypeService.selectSysIdentityTypeList(sysIdentityType);
        return getDataTable(list);
    }

    /**
     * 查询证件类型列表[不分页]
     */
    @PreAuthorize("@ss.hasPermi('system:identitytype:lists')")
    @GetMapping("/lists")
    public AjaxResult lists(SysIdentityType sysIdentityType) {
        List<SysIdentityType> list = sysIdentityTypeService.selectSysIdentityTypeList(sysIdentityType);
        return success(list);
    }

    /**
     * 导出证件类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:identitytype:export')")
    @Log(title = "证件类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysIdentityType sysIdentityType) {
        List<SysIdentityType> list = sysIdentityTypeService.selectSysIdentityTypeList(sysIdentityType);
        ExcelUtil<SysIdentityType> util = new ExcelUtil<SysIdentityType>(SysIdentityType.class);
        util.exportExcel(response, list, "证件类型数据");
    }

    /**
     * 获取证件类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:identitytype:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(sysIdentityTypeService.selectSysIdentityTypeById(id));
    }

    /**
     * 新增证件类型
     */
    @PreAuthorize("@ss.hasPermi('system:identitytype:add')")
    @Log(title = "证件类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysIdentityType sysIdentityType) {
        return toAjax(sysIdentityTypeService.insertSysIdentityType(sysIdentityType));
    }

    /**
     * 修改证件类型
     */
    @PreAuthorize("@ss.hasPermi('system:identitytype:edit')")
    @Log(title = "证件类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysIdentityType sysIdentityType) {
        return toAjax(sysIdentityTypeService.updateSysIdentityType(sysIdentityType));
    }

    /**
     * 删除证件类型
     */
    @PreAuthorize("@ss.hasPermi('system:identitytype:remove')")
    @Log(title = "证件类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(sysIdentityTypeService.deleteSysIdentityTypeByIds(ids));
    }

    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('system:identitytype:edit')")
    @Log(title = "证件类型", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody SysIdentityType sysIdentityType) {
        return toAjax(sysIdentityTypeService.updateSysIdentityTypeStatus(sysIdentityType));
    }
}
